Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create or update StorageClusterPeer #221

Merged
merged 4 commits into from
Oct 4, 2024

Conversation

vbnrh
Copy link
Member

@vbnrh vbnrh commented Jul 12, 2024

  • Updated MirrorPeerReconciler to handle StorageClientType by adding conditions in Reconcile method.
  • Introduced createStorageClusterPeer function for creating StorageClusterPeer objects.
  • Added utility functions fetchClientInfoConfigMap and getClientInfoFromConfigMap for handling client info.
  • Modified processManagedClusterAddon to utilize new config structure.
  • Enhanced DRPolicyReconciler to skip certain operations based on StorageClientType.

Copy link
Contributor

openshift-ci bot commented Jul 12, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vbnrh

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@vbnrh
Copy link
Member Author

vbnrh commented Jul 12, 2024

Commits contain changes from #220 and can be ignored

@vbnrh
Copy link
Member Author

vbnrh commented Jul 12, 2024

/test integration-test

@vbnrh vbnrh force-pushed the mirror-api-changes branch from a2f2376 to b912827 Compare July 12, 2024 13:22
@vbnrh vbnrh force-pushed the mirror-api-changes branch from b912827 to 686de01 Compare July 12, 2024 13:50
@vbnrh vbnrh changed the title Refactor MirrorPeerReconciler, API changes for StorageClient and deps updates API changes for StorageClient Jul 12, 2024
@vbnrh vbnrh force-pushed the mirror-api-changes branch 3 times, most recently from d5eb008 to 66aa1cd Compare July 17, 2024 04:22
@vbnrh vbnrh marked this pull request as draft July 17, 2024 04:23
@vbnrh vbnrh changed the title API changes for StorageClient Create or update StorageClusterPeer Jul 17, 2024
@vbnrh vbnrh force-pushed the mirror-api-changes branch from 66aa1cd to e7b374d Compare July 17, 2024 04:34
go.sum Outdated
@@ -711,8 +710,8 @@ github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3c
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/ramendr/ramen/api v0.0.0-20240409201920-10024cae3bfd h1:TsDaQqfb1BcR78JWXBmUyj6Qx4By5loUZ95CxmA/6zo=
github.com/ramendr/ramen/api v0.0.0-20240409201920-10024cae3bfd/go.mod h1:PCb0ODjdi4eYuxY/nSw+/rQqmzkmBVqGNoDr2JXdlKE=
github.com/red-hat-storage/ocs-operator/api/v4 v4.0.0-20240327160100-bbe9d9d49462 h1:84M7EBnmBISt2LcoyYPWsw+A3/7BGXp6Mh3sjUH5vIg=
github.com/red-hat-storage/ocs-operator/api/v4 v4.0.0-20240327160100-bbe9d9d49462/go.mod h1:uySjux/lY0DpC+VXof4ly2SlS7QUocTm2CH4sU8ICeg=
github.com/rewantsoni/ocs-operator/api/v4 v4.0.0-20240701052137-de69df292a5d h1:zXBbu5hpZmW4i3heppui4pqbvubZF/WsBiuP6ZekNKE=
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Temporarily till this merges red-hat-storage/ocs-operator#2466

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

red-hat-storage/ocs-operator#2677 is merged. We can update this.

go.mod Outdated
@@ -133,6 +133,7 @@ replace (
github.com/openshift/hive => github.com/openshift/hive v1.1.17-0.20220223000051-b1c8fa5853b1
github.com/openshift/hive/apis => github.com/openshift/hive/apis v0.0.0-20220221165319-b389a65758da
github.com/portworx/sched-ops => github.com/portworx/sched-ops v0.20.4-openstorage-rc3
github.com/red-hat-storage/ocs-operator/api/v4 => github.com/rewantsoni/ocs-operator/api/v4 v4.0.0-20240701052137-de69df292a5d
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be removed as soon as this merges red-hat-storage/ocs-operator#2466

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: red-hat-storage/ocs-operator#2677 is the PR, the older PR was before the design changes

Comment on lines 38 to 41
if peerRefs[0].StorageClusterRef.Namespace == "" && peerRefs[1].StorageClusterRef.Namespace == "" {
return true
}
return false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use Namespace empty as the condition to verify if it is a StorageClient or check for its existence?
We could simplify this to

return peerRefs[0].StorageClusterRef.Namespace == "" && peerRefs[1].StorageClusterRef.Namespace == "" 

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a MirrorPeer check to see if its client pairing . Later more changes will made to API to make it more explicit.

Comment on lines 387 to 388
func getClientInfoFromConfigMap(clientInfoMap map[string]string, clientName string) (ClientInfo, error) {
clientInfoJSON, ok := clientInfoMap[clientName]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vbnrh vbnrh force-pushed the mirror-api-changes branch 3 times, most recently from e43ec63 to 62202a2 Compare July 17, 2024 13:08
@vbnrh vbnrh force-pushed the mirror-api-changes branch from 8f86941 to 31b9f0e Compare July 22, 2024 11:25
@vbnrh vbnrh force-pushed the mirror-api-changes branch 3 times, most recently from 1aafe87 to 1a5c378 Compare July 24, 2024 11:16
@vbnrh vbnrh force-pushed the mirror-api-changes branch from 1a5c378 to 832ce81 Compare August 8, 2024 08:42
@vbnrh vbnrh marked this pull request as ready for review August 12, 2024 05:24
@vbnrh
Copy link
Member Author

vbnrh commented Aug 13, 2024

/test integration-test

Name string `json:"name"`
Name string `json:"name"`

// +kubebuilder:validation:Optional
Namespace string `json:"namespace"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Namespace string `json:"namespace"`
Namespace string `json:"namespace,omitempty"`

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

r.Logger.Error("Failed to create ODR ObjectBucketClaim", "error", err, "MirrorPeer", mirrorPeer.Name, "namespace", scNamespace)
return err
}
logger := r.Logger.With("MirrorPeer", mirrorPeer.Name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already set by the main Reconcile() function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -113,6 +113,11 @@ func (r *DRPolicyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
return ctrl.Result{}, err
}

if utils.IsStorageClientType(mirrorPeer.Spec.Items) {
logger.Info("MirrorPeer contains StorageClient reference. Skipping creation of VolumeReplicationClasses", "MirrorPeer", mirrorPeer.Name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.Info("MirrorPeer contains StorageClient reference. Skipping creation of VolumeReplicationClasses", "MirrorPeer", mirrorPeer.Name)
logger.Info("MirrorPeer contains StorageClient reference. Skipping creation of VolumeReplicationClasses")

Isn't MirrorPeer name already injected in the main reconcile function?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is DRPolicy controller, only the req is injected with the logger. MirrorPeer is fetched separately

const (
mirrorPeerFinalizer = "hub.multicluster.odf.openshift.io"
spokeClusterRoleBindingName = "spoke-clusterrole-bindings"
ClientConfigMapKeyTemplate = "%s/%s"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a constant.

Comment on lines 260 to 268
func getKey(clusterName, clientName string) string {
return fmt.Sprintf(ClientConfigMapKeyTemplate, clusterName, clientName)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this? I think Sprintf is good enough.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer it this way as it is more verbally descriptive. I will remove the clientconfigmapkey and use a format string

// Provider B's onboarding token will be used for Provider A's StorageClusterPeer
onboardingToken, err := fetchOnboardingTicket(ctx, client, oppositeClient, mirrorPeer)
if err != nil {
return ctrl.Result{}, fmt.Errorf("failed to fetch onboarding token for provider %s. err %w", oppositeClient.ProviderInfo.ProviderManagedClusterName, err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return ctrl.Result{}, fmt.Errorf("failed to fetch onboarding token for provider %s. err %w", oppositeClient.ProviderInfo.ProviderManagedClusterName, err)
return ctrl.Result{}, fmt.Errorf("failed to fetch onboarding token for provider %s. %w", oppositeClient.ProviderInfo.ProviderManagedClusterName, err)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -33,3 +33,7 @@ func GetPeerRefForSpokeCluster(mp *multiclusterv1alpha1.MirrorPeer, spokeCluster
}
return nil, fmt.Errorf("PeerRef for cluster %s under mirrorpeer %s not found", spokeClusterName, mp.Name)
}

func IsStorageClientType(peerRefs []multiclusterv1alpha1.PeerRef) bool {
return peerRefs[0].StorageClusterRef.Namespace == "" && peerRefs[1].StorageClusterRef.Namespace == ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't the right way to check this. IMO we need to cross-reference with our configmap.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

…pe handling

- Updated `MirrorPeerReconciler` to handle `StorageClientType` by adding conditions in `Reconcile` method.
- Introduced `createStorageClusterPeer` function for creating `StorageClusterPeer` objects.
- Added utility functions `fetchClientInfoConfigMap` and `getClientInfoFromConfigMap` for handling client info.
- Modified `processManagedClusterAddon` to utilize new config structure.
- Enhanced `DRPolicyReconciler` to skip certain operations based on `StorageClientType`.

Signed-off-by: vbadrina <[email protected]>
- New utility functions for checking if MirrorPeer is having StorageClient ref
- Functions cross check with the configmap to see if client
- Functions will take a parameter for managedCluster and hub cluster separately to
  pick the configmap properly

Signed-off-by: vbadrina <[email protected]>
- Upgrade `sigs.k8s.io/controller-runtime` to v0.19.0
- Upgrade Kubernetes modules to v0.31.0:
  - `k8s.io/api` v0.31.0
  - `k8s.io/apimachinery` v0.31.0
  - `k8s.io/client-go` v0.31.0
  - `k8s.io/apiextensions-apiserver` v0.31.0
- Update other dependencies to compatible versions
- Modify `Mirroring` field in `ocsv1.StorageClusterSpec` to use a pointer (`*ocsv1.MirroringSpec`)
- Update tests in:
  - `addons/agent_mirrorpeer_controller_test.go`
  - `addons/green_secret_controller_test.go`
- Run `go mod tidy` to clean up `go.mod` and `go.sum`
- Fix build errors due to mismatched dependencies and API changes

Signed-off-by: vbadrina <[email protected]>
@vbnrh vbnrh force-pushed the mirror-api-changes branch from 3c0cf48 to b4e0f4f Compare October 3, 2024 11:44
@openshift-ci openshift-ci bot added the lgtm label Oct 3, 2024
@vbnrh
Copy link
Member Author

vbnrh commented Oct 4, 2024

/test integration-test

@openshift-merge-bot openshift-merge-bot bot merged commit 8c27440 into red-hat-storage:main Oct 4, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants